<!DOCTYPE html>
<html class="ui-page-login">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<link href="css/login.css" rel="stylesheet" />
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">登录</h1>
		</header>
		<div class="mui-content">
			<form id='login-form' class="mui-input-group">
				<div class="mui-input-row">
					<label>账号：</label>
					<input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入用户名">
				</div>
				<div class="mui-input-row">
					<label>密码：</label>
					<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
			</form>
			<div id="tip">
			</div>
			<div class="mui-content-padded">
				<button id='login' class="mui-btn mui-btn-block mui-btn-primary">登录</button>
				<div class="link-area"><a id='reg'>注册账号</a> <span class="spliter">|</span> <a id='forgetPassword'>忘记密码</a>
				</div>
			</div>
			<div class="mui-content-padded oauth-area">

			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/mui.enterfocus.js"></script>
		<script src="js/app.js"></script>
		<script src="js/login.js"></script>
		<script>
			var Empls=null;
			function getXMLHttpRequest() {  
			    var xhr;  
			    try {  
			        xhr = new XMLHttpRequest();  
			    } catch (err1) {  
			        try {  
			            xhr = new ActiveXObject("Microsoft.XMLHTTP");  
			        } catch (err2) {  
			            alert("您的浏览器版本不支持Ajax....");  
			        }  
			    }  
			    return xhr;  
			}
			function saxJson() {
			    var xhr = getXMLHttpRequest();  
			    xhr.open("GET", "API/Data/empl.json", true);  
			    xhr.send();  
			    xhr.onreadystatechange = function() {  
			        if (xhr.readyState == 4 && xhr.status == 200) {
			        	Empls = eval("(" + xhr.responseText + ")").Empls;
			        }  
			    }
			} 
			saxJson();
			var loginButton = document.getElementById('login');
			var accountBox = document.getElementById('account');
			var passwordBox = document.getElementById('password');
			var tip = document.getElementById('tip');
			loginButton.addEventListener('tap', function(event) {
				var i=0;
				var loginInfo = {
					account: accountBox.value,
					password: passwordBox.value
				};
				var len = Empls.length;
				for(;i<len;i++){
					if(loginInfo.account==Empls[i].Name&&loginInfo.password==Empls[i].Mobile){
						tip.innerHTML="成功！";
						self.location='main.html?Name='+encodeURI(encodeURI(Empls[i].Name))+'&DeptID='+encodeURI(encodeURI(Empls[i].DeptID)); 
						return
					}else{
						tip.innerHTML="用户名或密码错误！";
					}
				}
			});
			

			mui.init({
				statusBarBackground: '#f7f7f7'
			});
			
			mui.plusReady(function() {
				var backButtonPress = 0;
				mui.back = function(event) {
					backButtonPress++;
					if (backButtonPress > 1) {
						plus.runtime.quit();
					} else {
						plus.nativeUI.toast('再按一次退出应用');
					}
					setTimeout(function() {
						backButtonPress = 0;
					}, 1000);
					return false;
				};
			});

		</script>
	</body>

</html>